<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
</head>
<body>
用户名：<input type="text" name="username" id="username">
<span id="msg" style="color: black">abc</span>
<br>
密码：<input type="password" name="password" id="password">

</body>
<script>
    let name = document.getElementById("username");
    let v = name.value;
    let msg = document.getElementById("msg");
    let t = function (resp) {
        console.log(resp.data);
        if (resp.data==1) {
            msg.innerHTML = "可以使用";
            msg.style.color="green";

        } else if (resp.data==-1){
            msg.innerHTML = "已被注册";
            msg.style.color="red";
        }else if(resp.data==0){
            msg.innerHTML="用户名不能为空";
            msg.style.color="brown";
        }
    }
    name.onblur = function () {
        v = name.value;
        let url = "registerServlet";
        let data = "username=" + v;
        axios.get(url + "?" + data).then(t);
    }


</script>
<script src="js/axios-0.18.0.js"></script>
</html>